<table class="ui-widget ui-widget-content" >
	<thead>
		<tr class="ui-widget-header" >
			<th>name</th>
			<th>subject</th>
			<th>#</th>
			<th>#</th>
			<th>#</th>
		</tr>
	</thead>
	<tbody>
	<?php
		$updateUrl = $this->url(array('ctrl' => 'tests', 'act' => 'update'));
		$deleteUrl = $this->url(array('ctrl' => 'tests', 'act' => 'delete'));
		$questionsUrl = $this->url(array('ctrl' => 'questions', 'act' => 'lists'));
		foreach ($this->tests as $test):
			?>
			<tr>
				<td><?php echo $this->escape($test->name);?></td>
				<td><?php echo $this->escape($test->subject);?></td>
				<td><a class="ajaxUpdateLink"  href="<?php echo $updateUrl.'&id='.$test->id;?>" >Update</a></td>
				<td><a class="ajaxDeleteLink"  href="<?php echo $deleteUrl.'&id='.$test->id;?>" >Delete</a></td>
				<td><a  href="<?php echo $questionsUrl.'&testId='.$test->id;?>" >Questions</a></td>
			</tr>
			<?php
		endforeach;?>
	</tbody>
</table>
<script type="text/javascript">
$(function(){
	var $testFormDialog = $('#testFormDialog');
	$testFormDialog.dialog({
		width:540,
		modal: true,
		autoOpen: false
	});
	$('.ajaxUpdateLink').click(function(){
		loadFormAndRefreshList(this, $testFormDialog, 'Update Test');
		return false;
	});
	$('.ajaxDeleteLink').click(function(){
		if(confirm("Are You sure???")){
			var $deleteLink = $(this); 
			$.ajax({
				dataType: 'json',
				url: $deleteLink.attr('href'),
				success: function(dataFromServer){
					if(dataFromServer && dataFromServer.isDeleted){
						$deleteLink.parents('tr').remove();
					}
				}
			});
		}
		return false;
	});
})
</script>